﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaMusaSoft.RPS.DataModel.Repositories;
using BaMusaSoft.RPS.DataModel;
using BaMusaSoft.RPS.RPSServices;
using BaMusaSoft.RPS.ViewModel.Infrastructure;
using BaMusaSoft.RPS.ViewModel.Properties;
using System.Globalization;
using System.Threading;
//using BaMusaSoft.NumToWords;
using System.Windows.Input;
using System.ComponentModel;
using System.Collections.ObjectModel;
using BaMusaSoft.RPS.ViewModel.HelperClasses;
using System.Windows.Data;
using System.Windows.Controls;
using BaMusaSoft.RPS.DataModel.Exceptions;
namespace BaMusaSoft.RPS.ViewModel
{
    public class ContractViewModel : Workspace
    {
        #region "Fields"

        private string _propertyNo;
        private readonly Settings _settings = Settings.Default;
        private IUnitOfWork _unitOfWork;
        private ContractsRepository _repository;

        #endregion

 

        #region "Printing Service"


        private void SetMargins(ContractMargins margins)
        {

            margins.SignDayStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_SignDayX),
                                                                  CmToYCordiniate(_settings.ContractForm_SignDayY));
            margins.SignHijriDateStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_SignHijriX),
                                                                        CmToYCordiniate(_settings.ContractForm_SignHijriY));
            margins.SingGregDateStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_SignGregX),
                                                                        CmToYCordiniate(_settings.ContractForm_SignGregY));

            margins.CustomerNameStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_CustomerNameX),
                                                                       CmToYCordiniate(_settings.ContractForm_CustomerNameY));

            margins.CustomerIdStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_CustomerIdX),
                                                                      CmToYCordiniate(_settings.ContractForm_CustomerIdY));

            margins.CustomerIdDateStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_CustomerIdDateX),
                                                                         CmToYCordiniate(_settings.ContractForm_CustomerIdDateY));

            margins.CustomerIdIssueStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_CustomerIdIssueX),
                                                                          CmToYCordiniate(_settings.ContractForm_CustomerIdIssueY));

            margins.CustomerAddressStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_CustomerAddressX),
                                                                          CmToYCordiniate(_settings.ContractForm_CustomerAddressY));

            margins.AgreedRentStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_AgreedRentX),
                                                                     CmToYCordiniate(_settings.ContractForm_AgreedRentY));
            margins.AgreedRentTextStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_AgreedRentTextX),
                                                                         CmToYCordiniate(_settings.ContractForm_AgreedRentTextY));


            margins.AgreedDepositStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_AgreedDepositX),
                                                                       CmToYCordiniate(_settings.ContractForm_AgreedDepositY));
            margins.AgreedDepositTextStartPoing = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_AgreedDepositTextX),
                                                                           CmToYCordiniate(_settings.ContractForm_AgreedDepositTextY));

            margins.ContractActivityStartPoing = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_ContractActivityX),
                                                                            CmToYCordiniate(_settings.ContractForm_ContractActivityY));

            margins.PropertyNoStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_PropertyNoX),
                                                                     CmToYCordiniate(_settings.ContractForm_PropertyNoY));
            margins.ProprtyLocationStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_PropertyLocationX),
                                                                          CmToYCordiniate(_settings.ContractForm_PropertyLocationY));
            margins.PropertyTypeStartPoint = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_PropertyTypeX),
                                                                      CmToYCordiniate(_settings.ContractForm_PropertyTypeY));
            margins.ContractPeriod = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_ContractPeriodX),
                                                                CmToYCordiniate(_settings.ContractForm_ContractPeriodY));
            margins.StartDate = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_StartDateX),
                                                                CmToYCordiniate(_settings.ContractForm_StartDateY));
            margins.EndDate = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_EndDateX),
                                                               CmToYCordiniate(_settings.ContractForm_EndDateY));
            margins.AgreedMaintinance = new System.Drawing.PointF(CmToXCordiniate(_settings.ContractForm_AgreedMaintX),
                                                               CmToYCordiniate(_settings.ContractForm_AgreedMaintY));
        }
        
        static float CmToXCordiniate(float cm)
        {
            return -(cm / 2.54f) * 100;
        }
        static float CmToYCordiniate(float cm)
        {
            return (cm / 2.54f) * 100;
        }
        #endregion

        #region "Helper Methods"
        private void RefreshBinding()
        {
            var bindableProperties = from p in typeof(ContractViewModel).GetProperties()
                                     where p.GetCustomAttributes(true).Cast<Attribute>().Contains(new BindableAttribute(true))
                                     select p;
            foreach (var p in bindableProperties)
            {
                RaisePropertyChanged(p.Name);
            }

        }
        #endregion

        #region Overrides of Workspace

        public override string DisplayName
        {
            get { throw new NotImplementedException(); }
            protected set { throw new NotImplementedException(); }
        }

        public override bool HasChanges
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

       
    }
}
